import request from "@/utils/request";
import { PersonContractForm } from "./types";
const currentSystem = localStorage.getItem("usertypeName");

/**
 * 新增合同
 *
 * @param data
 */
export function CreatePersonContract(data: PersonContractForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/contract/create";
      break;

    case "Corp":
      url = "/api/v1/corp/contract/create";
      break;
    case "Constructor":
      url = "/api/v1/constructor/contract/create";
      break;
    case "Manager":
      url = "/api/v1/manager/contract/create";
      break;
    case "Commander":
      url = "/api/v1/commander/contract/create";
      break;
    default:
      url = "/api/v1/sysuser/contract/create";
  }
  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 编辑合同
 *
 * @param data
 */
export function UpdatePersonContract(data: PersonContractForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/contract/update/";
      break;

    case "Corp":
      url = "/api/v1/corp/contract/update/";
      break;
    case "Constructor":
      url = "/api/v1/constructor/contract/update/";
      break;
    case "Manager":
      url = "/api/v1/manager/contract/update/";
      break;
    case "Commander":
      url = "/api/v1/commander/contract/update/";
      break;
    default:
      url = "/api/v1/sysuser/contract/update/";
  }
  return request({
    url: url + data.id,
    method: "put",
    data: data,
  });
}

/**
 * 获取分页
 *
 * @param data
 */
export function QueryPersonContractPage(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/contract/page";
      break;

    case "Corp":
      url = "/api/v1/corp/contract/page";
      break;
    case "Constructor":
      url = "/api/v1/constructor/contract/page";
      break;

    case "Manager":
      url = "/api/v1/manager/contract/page";
      break;
    case "Commander":
      url = "/api/v1/commander/contract/page";
      break;
    default:
      url = "/api/v1/sysuser/contract/page";
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取分页根据人员
 *
 * @param data
 */
export function QueryPersonContractPageByMemberId(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/contract/page_member";
      break;

    case "Corp":
      url = "/api/v1/corp/contract/page_member";
      break;
    case "Constructor":
      url = "/api/v1/constructor/contract/page_member";
      break;

    case "Manager":
      url = "/api/v1/manager/contract/page_member";
      break;
    case "Commander":
      url = "/api/v1/commander/contract/page_member";
      break;
    default:
      url = "/api/v1/sysuser/contract/page_member";
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取合同表单数据
 *
 * @param id
 */
export function GetPersonContractForm(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/contract/${id}`;
      break;

    case "Corp":
      url = `/api/v1/corp/contract/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/contract/${id}`;
      break;

    case "Manager":
      url = `/api/v1/manager/contract/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/contract/${id}`;
      break;
    default:
      url = `/api/v1/sysuser/contract/${id}`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取删除合同
 *
 * @param id
 */
export function DeletePersonContract(ids: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/contract/${ids}`;
      break;
    case "Corp":
      url = `/api/v1/corp/contract/${ids}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/contract/${ids}`;
      break;

    case "Manager":
      url = `/api/v1/manager/contract/${ids}`;
      break;
    case "Commander":
      url = `/api/v1/commander/contract/${ids}`;
      break;
    default:
      url = `/api/v1/sysuser/contract/${ids}`;
  }
  return request({
    url: url,
    method: "delete",
  });
}

/**
 * 根据身份证号获取合同详情列表
 *
 * @param id
 */
export function GetContractsByCardNumber(cardNumber: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/contract/getContractsByCardNumber/${cardNumber}`;
      break;
    case "Corp":
      url = `/api/v1/corp/contract/getContractsByCardNumber/${cardNumber}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/contract/getContractsByCardNumber/${cardNumber}`;
      break;

    case "Manager":
      url = `/api/v1/manager/contract/getContractsByCardNumber/${cardNumber}`;
      break;
    case "Commander":
      url = `/api/v1/commander/contract/getContractsByCardNumber/${cardNumber}`;
      break;
    default:
      url = `/api/v1/sysuser/contract/getContractsByCardNumber/${cardNumber}`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 根据身份证号获取合同详情列表
 *
 * @param id
 */
export function GetContractsByProjectAndCorpIdAndPersonId(personId: number, projectId: number, corpId: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/contract/getContractsByProjectAndCorpIdAndPersonId/${projectId}/${corpId}`;
      break;
    case "Corp":
      url = `/api/v1/corp/contract/getContractsByProjectAndCorpIdAndPersonId/${projectId}/${corpId}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/contract/getContractsByProjectAndCorpIdAndPersonId/${projectId}/${corpId}`;
      break;

    case "Manager":
      url = `/api/v1/manager/contract/getContractsByProjectAndCorpIdAndPersonId/${projectId}/${corpId}`;
      break;
    case "Commander":
      url = `/api/v1/commander/contract/getContractsByProjectAndCorpIdAndPersonId/${projectId}/${corpId}`;
      break;
    default:
      url = `/api/v1/sysuser/contract/getContractsByProjectAndCorpIdAndPersonId/${projectId}/${corpId}`;
  }
  return request({
    url: url,
    method: "get",
    params: {
      personId,
    },
  });
}
